package com.weiyi.mashangzhu.Landlord.Activity;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.Landlord.Adapter.DiscountAdapter;
import com.weiyi.mashangzhu.Landlord.Bean.DiscountBean;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.weiyi.mashangzhu.Weight.MyListView;
import com.weiyi.mashangzhu.Weight.WheelView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SetDiscountActivity extends BaseActivity {

    @BindView(R.id.weekend)
    MyListView weekend;
    @BindView(R.id.day_to_day)
    MyListView dayToDay;
    List<DiscountBean> weekendlist = new ArrayList<>();
    List<DiscountBean> daytodaylist = new ArrayList<>();
    TextView noset, five_six, six_seven, five_six_seven, pop_off;
    String date = "";
    WheelView wva;
    TextView affirm;
    TextView textView_price, textView_date, textView_7, textView_30;
    DiscountAdapter discountAdapter_weeked = null;
    DiscountAdapter discountAdapter_day = null;
    private static final String[] PLANETS = new String[]{"无折扣", "9折", "8折", "7折", "6折", "5折", "4折", "3折", "2折", "1折", "", "", ""};
    String info, id;
    String dis_date, dis_price, dis_7, dis_30;
    String dis_price_edit = null;
    String dis_date_edit = null;
    String dis_7_edit = null;
    String dis_30_edit = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_discount);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        info = intent.getStringExtra("info");
        id = intent.getStringExtra("id");
        if (MyApp.dis_price != null) {
            dis_price = MyApp.dis_price;
        } else {
            dis_price = null;
        }
        if (MyApp.dis_date != null) {
            dis_date = MyApp.dis_date;
        } else {
            dis_date = null;
        }
        if (MyApp.dis_7 != null) {
            dis_7 = MyApp.dis_7;
        } else {
            dis_7 = null;
        }
        if (MyApp.dis_30 != null) {
            dis_30 = MyApp.dis_30;
        } else {
            dis_30 = null;
        }

        weekendlist.add(new DiscountBean("选择日期", ""));
        weekendlist.add(new DiscountBean("设置价格", ""));
        daytodaylist.add(new DiscountBean("入住满7天", ""));
        daytodaylist.add(new DiscountBean("入住满三十天", ""));
        discountAdapter_weeked = new DiscountAdapter(weekendlist, this);
        weekend.setAdapter(discountAdapter_weeked);
        discountAdapter_day = new DiscountAdapter(daytodaylist, this);
        dayToDay.setAdapter(discountAdapter_day);

        if (info.equals("post")) {
            weekend.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    if (position == 0) {
                        showPopupWindow();
                    } else {
                        if (dis_date == null) {
                            T.showShort(SetDiscountActivity.this, "请先选择日期");
                        } else if (dis_date.equals("0")) {
                            T.showShort(SetDiscountActivity.this, "无折扣");
                        } else if (dis_date.equals("1")) {
                            price();
                        } else if (dis_date.equals("2")) {
                            price();
                        } else if (dis_date.equals("3")) {
                            price();
                        }

                    }
                }
            });
            dayToDay.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (position == 0) {
                        showPopupWindow_zhekou(7);
                    } else {
                        showPopupWindow_zhekou(30);
                    }

                }
            });
            if (MyApp.dis_price != null && !MyApp.dis_price.equals("")) {
                weekendlist.get(1).setCount(MyApp.dis_price + "元/每天");
                discountAdapter_weeked.notifyDataSetChanged();
            }
            if (MyApp.dis_date != null) {
                String date2 = "";
                if (MyApp.dis_date.equals("0")) {
                    date2 = "无";
//                    weekendlist.remove(1);
//                    discountAdapter_weeked.notifyDataSetChanged();
//                    weekend.getChildAt(1).setVisibility(View.GONE);

                } else if (MyApp.dis_date.equals("1")) {
                    date2 = "周五/周六";
//                    weekend.getChildAt(1).setVisibility(View.VISIBLE);
                }
                if (MyApp.dis_date.equals("2")) {
                    date2 = "周六/周日";
//                    weekend.getChildAt(1).setVisibility(View.VISIBLE);
                }
                if (MyApp.dis_date.equals("3")) {
                    date2 = "周五/周六/周日";
//                    weekend.getChildAt(1).setVisibility(View.VISIBLE);
                }
                weekendlist.get(0).setCount(date2);
                discountAdapter_weeked.notifyDataSetChanged();
            }
            if (MyApp.dis_7 != null) {
                String s = "";
                if (MyApp.dis_7.equals("10")) {
                    s = "无折扣";
                } else if (MyApp.dis_7.equals("9")) {
                    s = "9折";
                } else if (MyApp.dis_7.equals("8")) {
                    s = "8折";
                } else if (MyApp.dis_7.equals("7")) {
                    s = "7折";
                } else if (MyApp.dis_7.equals("6")) {
                    s = "6折";
                } else if (MyApp.dis_7.equals("5")) {
                    s = "5折";
                } else if (MyApp.dis_7.equals("4")) {
                    s = "4折";
                } else if (MyApp.dis_7.equals("3")) {
                    s = "3折";
                } else if (MyApp.dis_7.equals("2")) {
                    s = "2折";
                } else if (MyApp.dis_7.equals("1")) {
                    s = "1折";
                }
                daytodaylist.get(0).setCount(s);
                discountAdapter_day.notifyDataSetChanged();
            }
            if (MyApp.dis_30 != null) {
                String s = "";
                if (MyApp.dis_30.equals("10")) {
                    s = "无折扣";
                } else if (MyApp.dis_30.equals("9")) {
                    s = "9折";
                } else if (MyApp.dis_30.equals("8")) {
                    s = "8折";
                } else if (MyApp.dis_30.equals("7")) {
                    s = "7折";
                } else if (MyApp.dis_30.equals("6")) {
                    s = "6折";
                } else if (MyApp.dis_30.equals("5")) {
                    s = "5折";
                } else if (MyApp.dis_30.equals("4")) {
                    s = "4折";
                } else if (MyApp.dis_30.equals("3")) {
                    s = "3折";
                } else if (MyApp.dis_30.equals("2")) {
                    s = "2折";
                } else if (MyApp.dis_30.equals("1")) {
                    s = "1折";
                }
                daytodaylist.get(1).setCount(s);
                discountAdapter_day.notifyDataSetChanged();
            }
        } else {
            //修改房源
            weekend.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    if (position == 0) {
                        showPopupWindow();
                    } else {
                        if (dis_date_edit == null) {
                            T.showShort(SetDiscountActivity.this, "请先选择日期");
                        } else if (dis_date_edit.equals("0")) {
                            T.showShort(SetDiscountActivity.this, "无折扣");
                        } else if (dis_date_edit.equals("1")) {
                            price();
                        } else if (dis_date_edit.equals("2")) {
                            price();
                        } else if (dis_date_edit.equals("3")) {
                            price();
                        }

                    }
                }
            });
            dayToDay.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (position == 0) {
                        showPopupWindow_zhekou(7);
                    } else {
                        showPopupWindow_zhekou(30);
                    }

                }
            });
            LoadingDialog.show(this);
            OkHttpUtils.get()
                    .addParams("token", SPUtils.get(this, "token", "") + "")
                    .addParams("id", id)
                    .url(API.BaseApi_L + API.GetHouseDiscount)
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Request request, Exception e) {
                            T.showShort(SetDiscountActivity.this, "网络连接失败");
                            LoadingDialog.dismiss(SetDiscountActivity.this);
                        }

                        @Override
                        public void onResponse(String response) {
                            LoadingDialog.dismiss(SetDiscountActivity.this);
                            Log.e("ddddddddddd", "re=" + response);
                            try {
                                JSONObject jsonObject = new JSONObject(response);
                                if (jsonObject.getInt("status") == 0) {
                                    JSONArray jsonArray = jsonObject.getJSONArray("data");
                                    JSONObject jsonObject1 = jsonArray.getJSONObject(0);
                                    if (jsonObject1.getString("hWedate").equals("0")) {
//                                        weekend.getChildAt(1).setVisibility(View.GONE);
                                    } else {
//                                        weekend.getChildAt(1).setVisibility(View.VISIBLE);
                                        weekendlist.get(1).setCount(jsonObject1.getString("hWeprice") + "元/每晚");
                                    }
                                    if (jsonObject1.getString("hWedate").equals("0")) {
                                        weekendlist.get(0).setCount("不设置");
                                        dis_date_edit = "0";

                                    } else if (jsonObject1.getString("hWedate").equals("1")) {
                                        weekendlist.get(0).setCount("周五/周六");
                                        dis_date_edit = "1";
                                    }
                                    if (jsonObject1.getString("hWedate").equals("2")) {
                                        weekendlist.get(0).setCount("周六/周日");
                                        dis_date_edit = "2";
                                    }
                                    if (jsonObject1.getString("hWedate").equals("3")) {
                                        weekendlist.get(0).setCount("周五/周六/周日");
                                        dis_date_edit = "3";
                                    }
                                    //7天
                                    if (jsonObject1.getString("hSevendiscount").equals("10")) {
                                        daytodaylist.get(0).setCount("无折扣");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("9")) {
                                        daytodaylist.get(0).setCount("9折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("8")) {
                                        daytodaylist.get(0).setCount("8折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("7")) {
                                        daytodaylist.get(0).setCount("7折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("6")) {
                                        daytodaylist.get(0).setCount("6折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("5")) {
                                        daytodaylist.get(0).setCount("5折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("4")) {
                                        daytodaylist.get(0).setCount("4折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("3")) {
                                        daytodaylist.get(0).setCount("3折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("2")) {
                                        daytodaylist.get(0).setCount("2折");
                                    } else if (jsonObject1.getString("hSevendiscount").equals("1")) {
                                        daytodaylist.get(0).setCount("1折");
                                    }
                                    //30天
                                    if (jsonObject1.getString("hThirtydiscount").equals("10")) {
                                        daytodaylist.get(1).setCount("无折扣");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("9")) {
                                        daytodaylist.get(1).setCount("9折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("8")) {
                                        daytodaylist.get(1).setCount("8折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("7")) {
                                        daytodaylist.get(1).setCount("7折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("6")) {
                                        daytodaylist.get(1).setCount("6折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("5")) {
                                        daytodaylist.get(1).setCount("5折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("4")) {
                                        daytodaylist.get(1).setCount("4折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("3")) {
                                        daytodaylist.get(1).setCount("3折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("2")) {
                                        daytodaylist.get(1).setCount("2折");
                                    } else if (jsonObject1.getString("hThirtydiscount").equals("1")) {
                                        daytodaylist.get(1).setCount("1折");
                                    }

                                    discountAdapter_weeked.notifyDataSetChanged();
                                    discountAdapter_day.notifyDataSetChanged();
                                } else {
                                    T.showShort(SetDiscountActivity.this, jsonObject.getString("msg"));
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    });
        }


    }

    private void price() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        View view = View.inflate(this, R.layout.dialog_price_set, null);
        final TextView baocun = (TextView) view.findViewById(R.id.baocun);
        final EditText price = (EditText) view.findViewById(R.id.price);
        builder.setView(view);
        final AlertDialog dialog = builder.show();
        baocun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                textView_price = (TextView) weekend.getChildAt(1).findViewById(R.id.count);
                textView_price.setText(price.getText() + "元/每天");
                dis_price = price.getText() + "";

            }
        });
    }

    public void showPopupWindow() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_win_discount_date, null);
        final PopupWindow popupWindow = new PopupWindow(contentView,
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        noset = (TextView) contentView.findViewById(R.id.noset);
        five_six = (TextView) contentView.findViewById(R.id.five_sex);
        six_seven = (TextView) contentView.findViewById(R.id.six_seven);
        five_six_seven = (TextView) contentView.findViewById(R.id.five_six_seven);
        textView_date = (TextView) weekend.getChildAt(0).findViewById(R.id.count);
        noset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (info.equals("post")){
                    dis_date = "0";
                }else {
                    dis_date_edit = "0";
                    dis_price_edit="";
                }
                date = "不设置";
                weekendlist.get(0).setCount(date);
                weekendlist.get(1).setCount("");
                discountAdapter_weeked.notifyDataSetChanged();
                popupWindow.dismiss();
            }
        });
        five_six.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                date = "周五/周六";
                dis_date = "1";
                dis_date_edit = "1";
                textView_date.setText( "周五/周六");
                popupWindow.dismiss();
            }
        });
        six_seven.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                date = "周六/周日";
                dis_date = "2";
                dis_date_edit = "2";
                textView_date.setText("周六/周日");
                popupWindow.dismiss();
            }
        });
        five_six_seven.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                date = "周五/周六/周日";
                dis_date = "3";
                dis_date_edit = "3";
                textView_date.setText("周五/周六/周日");
                popupWindow.dismiss();
            }
        });

        pop_off = (TextView) contentView.findViewById(R.id.pop_off);
        pop_off.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        popupWindow.setTouchable(true);
        popupWindow.setAnimationStyle(R.style.popup_window_bottom_animation);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x55000000));
        // 设置好参数之后再show
        if (popupWindow.isShowing()) {

        } else {
            popupWindow.showAsDropDown(contentView);
        }

    }

    private void showPopupWindow_zhekou(final int daycount) {
        View contentView = null;
        //设置contentView
        contentView = LayoutInflater.from(this).inflate(R.layout.mywheelview, null);
        wva = (WheelView) contentView.findViewById(R.id.main_wv);
        affirm = (TextView) contentView.findViewById(R.id.queren);

        wva.setOffset(1);
        wva.setItems(Arrays.asList(PLANETS));

        wva.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                Log.d("qqqqqqqq", "selectedIndex: " + selectedIndex + ", item: " + item);
            }
        });


        final PopupWindow mPopWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(contentView);
        mPopWindow.setAnimationStyle(R.style.popup_window_bottom_animation);
        mPopWindow.showAtLocation(contentView, Gravity.BOTTOM, 0, 0);
        mPopWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        mPopWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.5f;
        getWindow().setAttributes(lp);
        affirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String string = wva.getSeletedItem();
                String s = "";
                if (string.equals("无折扣")) {
                    s = "10";
                } else if (string.equals("9折")) {
                    s = "9";
                } else if (string.equals("8折")) {
                    s = "8";
                } else if (string.equals("7折")) {
                    s = "7";
                } else if (string.equals("6折")) {
                    s = "6";
                } else if (string.equals("5折")) {
                    s = "5";
                } else if (string.equals("4折")) {
                    s = "4";
                } else if (string.equals("3折")) {
                    s = "3";
                } else if (string.equals("2折")) {
                    s = "2";
                } else if (string.equals("1折")) {
                    s = "1";
                }
                mPopWindow.dismiss();
                if (daycount == 7) {
                    textView_7 = (TextView) dayToDay.getChildAt(0).findViewById(R.id.count);
                    textView_7.setText(string);
                    dis_7 = s;
                } else {
                    textView_30 = (TextView) dayToDay.getChildAt(1).findViewById(R.id.count);
                    textView_30.setText(string);
                    dis_30 = s;
                }

            }
        });
        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);

            }
        });
    }

    @OnClick({R.id.back, R.id.baocun})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.baocun:
                if (info.equals("post")) {
                    Intent intent = new Intent();
                    if (dis_date != null && dis_7 != null && dis_30 != null) {
                        MyApp.dis_date = dis_date;
                        MyApp.dis_7 = dis_7;
                        MyApp.dis_30 = dis_30;
                        if (dis_price == null) {
                            MyApp.dis_price = "";
                        } else {
                            MyApp.dis_price = dis_price;
                        }
                        intent.putExtra("info", "完成");
                        setResult(0x003, intent);
                        finish();
                    } else {
                        T.showShort(SetDiscountActivity.this, "请完善折扣信息");
//                        intent.putExtra("info", "未完成");
                    }

                } else {
                    LoadingDialog.show(this);

                    TextView date = (TextView) weekend.getChildAt(0).findViewById(R.id.count);
                    TextView price = (TextView) weekend.getChildAt(1).findViewById(R.id.count);
                    TextView dis7 = (TextView) dayToDay.getChildAt(0).findViewById(R.id.count);
                    TextView dis30 = (TextView) dayToDay.getChildAt(1).findViewById(R.id.count);
                    if ((date.getText() + "").equals("不设置")) {
                        dis_date_edit = "0";
                    } else if ((date.getText() + "").equals("周五/周六")) {
                        dis_date_edit = "1";
                    }
                    if ((date.getText() + "").equals("周六/周日")) {
                        dis_date_edit = "2";
                    }
                    if ((date.getText() + "").equals("周五/周六/周日")) {
                        dis_date_edit = "3";
                    }
                    if ((dis7.getText() + "").equals("无折扣")) {
                        dis_7_edit = "10";
                    } else if ((dis7.getText() + "").equals("9折")) {
                        dis_7_edit = "9";
                    } else if ((dis7.getText() + "").equals("8折")) {
                        dis_7_edit = "8";
                    } else if ((dis7.getText() + "").equals("7折")) {
                        dis_7_edit = "7";
                    } else if ((dis7.getText() + "").equals("6折")) {
                        dis_7_edit = "6";
                    } else if ((dis7.getText() + "").equals("5折")) {
                        dis_7_edit = "5";
                    } else if ((dis7.getText() + "").equals("4折")) {
                        dis_7_edit = "4";
                    } else if ((dis7.getText() + "").equals("3折")) {
                        dis_7_edit = "3";
                    } else if ((dis7.getText() + "").equals("2折")) {
                        dis_7_edit = "2";
                    } else if ((dis7.getText() + "").equals("1折")) {
                        dis_7_edit = "1";
                    }
                    if ((dis30.getText() + "").equals("无折扣")) {
                        dis_30_edit = "10";
                    } else if ((dis30.getText() + "").equals("9折")) {
                        dis_30_edit = "9";
                    } else if ((dis30.getText() + "").equals("8折")) {
                        dis_30_edit = "8";
                    } else if ((dis30.getText() + "").equals("7折")) {
                        dis_30_edit = "7";
                    } else if ((dis30.getText() + "").equals("6折")) {
                        dis_30_edit = "6";
                    } else if ((dis30.getText() + "").equals("5折")) {
                        dis_30_edit = "5";
                    } else if ((dis30.getText() + "").equals("4折")) {
                        dis_30_edit = "4";
                    } else if ((dis30.getText() + "").equals("3折")) {
                        dis_30_edit = "3";
                    } else if ((dis30.getText() + "").equals("2折")) {
                        dis_30_edit = "2";
                    } else if ((dis30.getText() + "").equals("1折")) {
                        dis_30_edit = "1";
                    }
                    if ((date.getText() + "").equals("不设置")) {
                        dis_price_edit = "";
                    } else {
                        if (!(price.getText() + "").equals("")){
                            dis_price_edit = (price.getText() + "").substring(0, (price.getText() + "").indexOf("元"));
                        }else {
                            dis_price_edit ="";
                        }

                    }
                    Log.e("dddddddddddddd", "re3=" + SPUtils.get(this, "token", "") + "");
                    Log.e("dddddddddddddd", "re3=" + id);
                    Log.e("dddddddddddddd", "re3=" + dis_date_edit);
                    Log.e("dddddddddddddd", "re3=" + dis_price_edit);
                    Log.e("dddddddddddddd", "re3=" + dis_7_edit);
                    Log.e("dddddddddddddd", "re3=" + dis_7_edit);
                    OkHttpUtils.get()
                            .addParams("token", SPUtils.get(this, "token", "") + "")
                            .addParams("id", id)
                            .addParams("hWedate", dis_date_edit)
                            .addParams("hWeprice", dis_price_edit)
                            .addParams("hSevendiscount", dis_7_edit)
                            .addParams("hThirtydiscount", dis_30_edit)
                            .url(API.BaseApi_L + API.UpdateHouseDiscount)
                            .build()
                            .execute(new StringCallback() {
                                @Override
                                public void onError(Request request, Exception e) {
                                    LoadingDialog.dismiss(SetDiscountActivity.this);
                                    T.showShort(SetDiscountActivity.this, "网络连接失败");
                                }

                                @Override
                                public void onResponse(String response) {
                                    LoadingDialog.dismiss(SetDiscountActivity.this);
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        if (jsonObject.getInt("status") == 0) {
                                            T.showShort(SetDiscountActivity.this, jsonObject.getString("msg") + " 后台审核中...");
                                            finish();
                                        } else {
                                            T.showShort(SetDiscountActivity.this, jsonObject.getString("msg"));
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            });


                }

                break;
        }
    }
}
